<?php

namespace app\admin\model\goods;

use think\Model;


class Classadd extends Model
{

    

    

    // 表名
    protected $name = 'goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'addtime_text',
        'kind_text',
        'is_school_text'
    ];
    

    
    public function getKindList()
    {
        return ['1' => __('Kind 1'), ' 2' => __('Kind  2')];
    }

    public function getIsSchoolList()
    {
        return ['1' => __('Is_school 1'), ' 0' => __('Is_school  0'), ' 2' => __('Is_school  2')];
    }


    public function getAddtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['addtime']) ? $data['addtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getKindTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['kind']) ? $data['kind'] : '');
        $list = $this->getKindList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsSchoolTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_school']) ? $data['is_school'] : '');
        $list = $this->getIsSchoolList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setAddtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
